using System;
using FU.Capstones.IMS.Web.Common;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.DataContracts;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.EventArgs;

namespace FU.Capstones.IMS.Web.Silverlight.Models
{
    public class MaterialDetailModel : ModelBase
    {
        public MaterialDetailModel()
        {
            client.GetSingleMaterialCompleted += DoGetSingleMaterialCompleted;
            client.InsertMaterialCompleted += DoInsertMaterialCompleted;
            client.UpdateMaterialCompleted += DoUpdateMaterialCompleted;
        }

        #region UpdateMaterial

        public event EventHandler<FeedbackCompletedEventArgs> UpdateMaterialCompleted;

        public int UpdateMaterialAsync(Material data)
        {
            client.UpdateMaterialAsync(data);
            return WebConstants.MagicNumer;
        }

        void DoUpdateMaterialCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (UpdateMaterialCompleted != null)
            {
                UpdateMaterialCompleted(sender, e);
            }
        }

        #endregion

        #region InsertMaterial

        public event EventHandler<SingleFeedbackCompletedEventArgs<int>> InsertMaterialCompleted;

        public int InsertMaterialAsync(Material data)
        {
            client.InsertMaterialAsync(data);
            return WebConstants.MagicNumer;
        }

        void DoInsertMaterialCompleted(object sender, SingleFeedbackCompletedEventArgs<int> e)
        {
            if (InsertMaterialCompleted != null)
            {
                InsertMaterialCompleted(sender, e);
            }
        }

        #endregion

        #region GetSingleMaterial

        public event EventHandler<SingleFeedbackCompletedEventArgs<Material>> GetSingleMaterialCompleted;

        public int GetSingleMaterialAsync(int objID)
        {
            client.GetSingleMaterialAsync(objID);
            return WebConstants.MagicNumer;
        }

        void DoGetSingleMaterialCompleted(object sender, SingleFeedbackCompletedEventArgs<Material> e)
        {
            if (GetSingleMaterialCompleted != null)
            {
                GetSingleMaterialCompleted(sender, e);
            }
        }

        #endregion
    }
}